var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //tabs: ['待抢购', '在进行', '已结束'],
    tabIndex: 1,
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
    is_open: 1
  },
  backto: function (e) {
    wx.navigateBack({})
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      tabs: ['待' + options.title, '在进行', '已结束'],
      tabs_title: options.title,
      tabs_type: options.type
    })
    var that = this;
    if (!app.globalData.userInfo) {
      app.getUserInfo();
    }
    this.setData({
      userInfo: app.globalData.userInfo,
    })
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }
    });
    app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/' + options.type, res=>{
      var goods_list = res.data
      var pin = 0, kan = 0, qiang = 0
      for (var i = 0;i < 3;i++) {
        if (goods_list[i].length != 0) {
          for (var j = 0; j < goods_list[i].length;j++) {
            options.type == 'pin' ? pin = 1 : ''
            options.type == 'kan' ? kan = 1 : ''
            options.type == 'qiang' ? qiang = 1 : ''
            goods_list[i][j].is_pin = pin
            goods_list[i][j].is_kan = kan
            goods_list[i][j].is_qiang = qiang
          }
        }
      }
      this.setData({
        goods_list: goods_list
      })
    })
    app.ihttpGet("https://www.58zltc.com/api.php/Shop/getTCCPrice", function (res) {
      var data = res.data;
      that.setData({
        agree_str: data.agree,
        card: data.card,
        mycard:data.mycard,
        pic:data.pic
      })
    });
    //是否开过卡
    app.ihttpGet("https://www.58zltc.com/api.php/Shop/haveTCCard/openid/" + app.globalData.openid, function (res) {
      var data = res.data;
      that.setData({
        is_open: data.have_car,
        car_info: data.info
      })
    });
  },
  bindChange: function (e) {

    var that = this;
    that.setData({ currentTab: e.detail.current });

  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
    //砍价检索
    if (that.data.tabs_title == '砍价') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/kan/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
    //抢购检索
    if (that.data.tabs_title == '抢购') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/qiang/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
    //拼团检索
    if (that.data.tabs_title == '拼团') {
      console.log(that.data.tabs_title)
      app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/huodong/pin/clickType/' + e.target.dataset.current, res => {
        that.setData({
          goods_list: res.data
        })
      })
    }
  },
  setTab: function (e) {
    // console.log(e);
    var index = e.currentTarget.dataset.index;
    this.setData({
      tabIndex: index
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that = this;
    var pages = getCurrentPages();
    var currentPage = pages[pages.length - 1];
    var url = currentPage.route;
    return {
      title: '庆云同城',
      path: '/' + url + '?type=' + that.data.tabs_type + '&title=' + that.data.tabs_title,
      success: function (res) {},
      fail: function (res) {}
    }
  },
  jumptccar: function () {
    wx.navigateTo({
      url: '/pages/shop/tccar/tccar',
    })
  }
})